(function (window, undefined) {
    $.fn.lazyload = function () {

        let _this = this
        let t = null

        function lazyLoad() {

            if (t) clearTimeout(t)
            t = setTimeout(() => {
                // 获取可视窗口
                var windowH = window.innerHeight || document.documentElement.clientHeight
                var scrollH = document.documentElement.scrollTop || document.body.scrollTop
                let show = windowH + scrollH
                //
                console.log(_this);
                //遍历
                for (let i = 0; i < _this.length; i++) {
                    //    判断如果图片距离窗口高度大于可视高度则不加载 小于加载
                    if (_this[i].offsetTop < show) {
                        _this[i].src = _this[i].getAttribute('data-src')
                    }
                }
            }, 100)
        }
        lazyLoad()
        window.onscroll = lazyLoad
    }
})(window)